#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time     : 2021/6/25 15:41
# @Author   : chengfeng
# @Email    : chengfeng@inhand.com.cn
# @File     : commom_step.py

from Element.element import Login
from Conf.Config import Config
import allure
from Common import Assert
import logging
conf = Config()
login_page = Login()


@allure.step("打开路由器web页面")
def goto_route(page):
    page.goto('{}://{}'.format(conf.protocol, conf.host), wait_utill='load')
    Assert.placeholder(page, login_page.userInput_selector, login_page.userInput_placeholder)
    Assert.placeholder(page, login_page.pswdInput_selector, login_page.pswdInput_placeholder)
    logging.info('Open route address {}://{}'.format(conf.protocol, conf.host))


@allure.step("输入用户名")
def input_username(page, username):
    page.click(login_page.userInput_selector)
    page.fill(login_page.userInput_selector, username)
    logging.info("Input username {}".format(username))


@allure.step("输入密码")
def input_password(page, password):
    page.click(login_page.pswdInput_selector)
    page.fill(login_page.pswdInput_selector, password)
    logging.info("Input password is {}".format(password))


@allure.step("点击登录按钮")
def submit_login(page):
    page.click(login_page.loginButton_selector)
    logging.info("Click login button")
